package com.abss.vote.mapper;

import com.abss.vote.model.ActivityWorkVo;
import com.abss.vote.model.UserVotesInfo;
import com.abss.vote.model.Votes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface VotesMapper {

    int addVote(ActivityWorkVo activityWorkVo);

    @Select("select count(ID) from VOTES where ACTIVITY_ID=#{ACTIVITY_ID} and USER_ID=#{USER_ID} and WORK_ID=#{WORK_ID} and DateDiff(dd,DTIME,getdate())=0")
    int getVotesNum(ActivityWorkVo activityWorkVo);

    List<Votes> getAllVotes();

    int addVotes(Votes votes);

    @Select("select * from USER_VOTES_INFO where ACTIVITY_ID=#{ACTIVITY_ID} and USER_ID=#{USER_ID}")
    List<Votes> getUserVotesInfo(Votes votes);

    int upUserVotesInfo(Votes votes);

    int addUserVotesInfo(Votes votes);

    @Select("select u.* from USER_VOTES_INFO u left join ACTIVITY a on u.ACTIVITY_ID=a.ACTIVITY_ID where a.REMOVE=0 and a.DELETED=0 and a.IS_VOTE=1")
    List<UserVotesInfo> getVotes();

    @Select("select * from USER_VOTES_INFO where ACTIVITY_ID=#{ACTIVITY_ID} and REMOVE=0 order by LAST_UPDATE_TIME desc")
    List<UserVotesInfo> getUserVotesList(UserVotesInfo userVotesInfo);

    @Update("update USER_VOTES_INFO set REMOVE=1,REMOVER=#{REMOVER},REMOVE_TIME=GETDATE() where ID=#{ID}")
    int deleteUserVote(@Param("ID") String ID, @Param("REMOVER") String REMOVER);
}
